@extends('admin.layout.admin_main')

@section('content')
    <link rel="stylesheet" href="{{asset('plugins/nestable/nestable.css')}}">
    <script src="{{asset('plugins/nestable/jquery.nestable.js')}}"></script>
    <section class="content ">
        <include file="Public/common/message"/>
        <div class="row">
            @include('admin.auth.common.sys_menu',['name' => 'menu'])
            <div class="col-md-6">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">菜单树</h3>
                        <div class="box-tools pull-right">
                            @if (Auth::guard('admin')->user()->canPerm('admin-menu-create'))
                            <a href="/admin/menu/create" class="btn btn-primary pull-right btn-sm"><i class="fa fa-plus"></i> 添加菜单</a>
                            @endif
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box">
                        <div class="box-body table-responsive">
                            <div class="dd">
                                <ol class="dd-list">
                                @foreach($list as $item)
                                        <li class="dd-item" data-id="{{$item['id']}}">
                                            <button data-action="collapse" type="button">Collapse</button>
                                            <button data-action="expand" type="button" style="display: none;">Expand</button>
                                            <div class="dd-handle">
                                                <i class="{{$item['icon']}}"></i>&nbsp;<strong>{{$item['title']}}</strong>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{{$item['uri']}}" class="dd-nodrag">{{$item['uri']}}</a>
                                                <span class="pull-right dd-nodrag">
                                                    @if (Auth::guard('admin')->user()->canPerm('admin-menu-edit'))
                                                    <a href="/admin/menu/{{$item['id']}}/edit"><i class="fa fa-edit"></i></a>
                                                    @endif
                                                    @if (Auth::guard('admin')->user()->canPerm('admin-menu-delete'))
                                                    <a href="javascript:void(0);" data-id="{{$item['id']}}" class="tree_branch_delete"><i class="fa fa-trash"></i></a>
                                                    @endif
                                                </span>
                                            </div>
                                            @if(isset($item['items']))
                                            <ol class="dd-list">
                                            @foreach($item['items'] as $vo)
                                                    <li class="dd-item" data-id="{{$vo['parent_id']}}">
                                                        <div class="dd-handle">
                                                            <i class="{{$vo['icon']}}"></i>&nbsp;<strong>{{$vo['title']}}</strong>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{{$vo['uri']}}" class="dd-nodrag">{{$vo['uri']}}</a>
                                                            <span class="pull-right dd-nodrag">
                                                                @if (Auth::guard('admin')->user()->canPerm('admin-menu-edit'))
                                                                <a href="/admin/menu/{{$vo['id']}}/edit"><i class="fa fa-edit"></i></a>
                                                                @endif
                                                                @if (Auth::guard('admin')->user()->canPerm('admin-menu-delete'))
                                                                <a href="javascript:void(0);"  data-url="/admin/menu/{{$vo['id']}}/delete" onclick="nform.delete(this)"class="tree_branch_delete"><i class="fa fa-trash"></i></a>
                                                                @endif
                                                            </span>
                                                        </div>
                                                    </li>
                                            @endforeach
                                            </ol>
                                            @endif
                                        </li>
                                @endforeach
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4" style="padding-left: 0px;">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">添加菜单</h3>
                        <div class="box-tools pull-right">
                        </div>
                    </div>
                    <div class="box">
                        @if (Auth::guard('admin')->user()->canPerm('admin-menu-create'))
                        @include('admin.auth.menu.add')
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </section>
    <script>
        $(function () {
            $('.dd-item').on('click', function(e){
                var target = $(e.target),
                    action = target.data('action');
                if (action === 'expand') {
                    $('.dd').nestable('expandAll');
                }
                if (action === 'collapse') {
                    $('.dd').nestable('collapseAll');
                }
            });
        });
    </script>
@endsection
